package com.lq.demo.demo;

import java.lang.reflect.Field;

public class Test {

    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        Integer a = 1;
        Integer b = 2;

        System.out.println(" before a:" + a + "  b:" + b);
        swap(a, b);
        System.out.println(" after a:" + a + "  b:" + b);

    }

    private static void swap(Integer a, Integer b) throws NoSuchFieldException, IllegalAccessException {
        Field value = Integer.class.getDeclaredField("value");
        value.setAccessible(true);
        int temp = a.intValue();
        value.set(a, b);
        System.out.println(b);
        Integer s = new Integer(temp);
        value.set(b,s);

    }


}
